package com.spica.spicaschool.ui.likelist

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import coil.load
import coil.transform.CircleCropTransformation
import com.drakeet.multitype.ItemViewDelegate
import com.spica.spicaschool.R
import com.spica.spicaschool.bean.like.Like
import com.spica.spicaschool.databinding.ItemLikeBinding

/**
 * 点赞列表的适配器
 */
class LikeDelegate(val context: Context) : ItemViewDelegate<Like, LikeDelegate.ViewHolder>() {

    class ViewHolder(val viewBiding: ItemLikeBinding) : RecyclerView.ViewHolder(viewBiding.root)

    override fun onBindViewHolder(holder: ViewHolder, item: Like) {
        with(holder.viewBiding) {
            ivAvatar.load(item.user.uAvatar) {
                placeholder(R.drawable.default_head)
                error(R.drawable.default_head)
                transformations(CircleCropTransformation())
            }
            tvUserName.text = item.user.uNickname
        }
    }

    // override fun getItemId(item: User): Long = item.uId.toUid().toLong()

    override fun onCreateViewHolder(context: Context, parent: ViewGroup): ViewHolder {
        val viewBinding = ItemLikeBinding.inflate(LayoutInflater.from(context), parent, false)
        return ViewHolder(viewBinding)
    }
}
